<?php
/**
 * Created by PhpStorm.
 * User: eks
 * Date: 2023/6/1
 * Time: 19:10
 */

namespace App\Http\Controllers;

use App\Datas\AfLog;
use App\Datas\EventList;
use App\Datas\Pay;
use App\Datas\System;
use App\Datas\User;
use App\Datas\Upgrade;
use App\Datas\Opus;
use App\Tools\Oppo;
use App\Tools\Oss;
use App\Tools\Huawei;
use App\Tools\Curl as CurlCommon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Ixudra\Curl\Facades\Curl;

//use GeoIp2\Database\Reader;

use App\Datas\UserGoogleSubscribe;


class ManageController extends Controller {
	protected $dataUser;
	protected $dataSystem;
	protected $dataOpus;

	public function __construct() {
		$this->dataUser = new User();
		$this->dataSystem = new System();
		$this->dataOpus = new Opus();
	}

	/**
	 * 用户生成图片列表
	 */
	public function getOpusList(Request $request) {
		$aWhere['user_id'] = $request->post('user_id');//
		$aWhere['create_date'] = $request->post('create_date');//
		$aWhere['create_egt'] = $request->post('create_egt');//>=
		$aWhere['create_elt'] = $request->post('create_elt');//<=

		$iPage = $request->post('page', 1);//
		$iPageSize = 20;//

		$aResult['list'] = $this->dataOpus->getOpusList($aWhere, $iPage, $iPageSize);
		$aResult['total'] = $this->dataOpus->getOpusAmount($aWhere);
		$aResult['page_size'] = $iPageSize;
		$aResult['page_total'] = ceil($aResult['total'] / $iPageSize);

		return $this->buildReturn(Code::SUCCESS, $aResult);
	}

	/**
	 * 审核生成图片
	 */
	public function verifyOpus(Request $request) {
		$iID = $request->post('id');//
		$iIsVerify = $request->post('is_verify');//

		$aUpdate = [];
		$sUrl = 'https://overseas-files.dalleai.art/default-audit-failure.png';
		if(2 == $iIsVerify) {
			$aUpdate['url'] = $sUrl;
			$aUpdate['updated_at'] = date('Y-m-d H:i:s');
			$aUpdate['is_verify'] = 2;

			$aData = $this->dataOpus->getOpusByID($iID);
			if(isset($aData['url']) && !empty($aData['url'])) {
				$sDomain = 'https://overseas-files.dalleai.art';
				$sPath = str_replace($sDomain, '', $aData['url']);

				$oOss = new Oss();
				$oOss->deleteObject($sPath);
			}
		}

		$aResult['status'] = $this->dataOpus->updateOpusByID($iID, $aUpdate);
		$aResult['url'] = $sUrl;

		return $this->buildReturn(Code::SUCCESS, $aResult);
	}

	/**
	 * @param Request $request
	 * @return array
	 */
	public function login(Request $request){
		$sAccount = $request->post('account');//
		$sPWD = $request->post('password');//

		$aResult = [];

		return $this->buildReturn(Code::SUCCESS, $aResult);
	}

}